package chenjiuxu.seniorui.study;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.SweepGradient;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 15705 on 2017/12/25.
 * 渐变渲染/梯度渲染
 */
public class SweepGradienView extends View {
    private final Paint paint;

    public SweepGradienView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int w = getWidth();
        int h = getHeight();
        int[] colors = new int[]{Color.BLACK, Color.TRANSPARENT, Color.WHITE, Color.BLUE};
        float[] positions = null;
        SweepGradient sweepGradient = new SweepGradient(w / 2, h / 2, colors, positions);
        paint.setShader(sweepGradient);
        canvas.drawCircle(w / 2, w / 2, w / 2, paint);
    }
}
